home *** CD-ROM | disk | FTP | other *** search
/ Amiga Plus 1995 #2 / Amiga Plus CD - 1995 - No. 2.iso / pd / mui / casslabel / source / output.c < prev    next >
C/C++ Source or Header  |  1995-04-11  |  8KB  |  269 lines

  1. /* $VER: output.c 2.1 (05.06.94)
  2.  */
  3.  
  4. #include "global.h"
  5.  
  6. /* Locale support */
  7. #define CATCOMP_NUMBERS
  8. #define CATCOMP_BLOCK
  9. #include "CassLabel_strings.h"
  10.  
  11.  
  12. /**********************************************************************
  13.  *                        Generate the output                         *
  14.  **********************************************************************/
  15. void generate_file(char *path)
  16. {
  17.     char *pos1, *pos2;
  18.     char bufline1[256], bufline2[256], argline[8][256];
  19.     int buflineflag = 0, arglinecount = 0;
  20.     struct NodeEntry *entry, emptynode = {"", ""};
  21.     long endA, endB, translateflag;
  22.     FILE *fh, *out;
  23.  
  24.     /* Get number of all entries */
  25.     get(LV_SideA, MUIA_List_Entries, &endA);
  26.     get(LV_SideB, MUIA_List_Entries, &endB);
  27.  
  28.     /* Get state of Translate-Checkmark */
  29.     get(CM_Translate, MUIA_Selected, &translateflag);
  30.  
  31.     if ((fh = fopen(GetStr(PS_PopFormat_String), "r")) && (out = fopen(path, "w")))
  32.     {
  33.         while (pos1 = fgets(bufline1, 256, fh))
  34.         {
  35.             if (bufline1[0] == '@')
  36.             {
  37.                 /* Read in argline */
  38.                 pos1++;
  39.                 while (*pos1 != '\n')
  40.                 {
  41.                     pos2 = strchr(pos1, '@');
  42.                     *pos2++ = '\0';
  43.  
  44.                     /* Insert the common entries */
  45.                     if (!strcmp(pos1,"POSITION"))
  46.                             strcpy(argline[arglinecount++], CYA_Position[GetCycle(CY_Position)]);
  47.                     if (!strcmp(pos1,"LENGTH"))
  48.                             strcpy(argline[arglinecount++], CYA_Length[GetCycle(CY_Length)]);
  49.                     if (!strcmp(pos1,"NUMBER"))
  50.                             strcpy(argline[arglinecount++], GetStr(ST_Number));
  51.  
  52.                     if (!strcmp(pos1,"TOPTITLE_A"))
  53.                         if (translateflag)
  54.                             strcpy(argline[arglinecount++], translate_to_latex(GetStr(ST_TitleA)));
  55.                         else
  56.                             strcpy(argline[arglinecount++], GetStr(ST_TitleA));
  57.                     if (!strcmp(pos1,"TOPGROUP_A"))
  58.                         if (translateflag)
  59.                             strcpy(argline[arglinecount++], translate_to_latex(GetStr(ST_GroupA)));
  60.                         else
  61.                             strcpy(argline[arglinecount++], GetStr(ST_GroupA));
  62.                     if (!strcmp(pos1,"DATE_A"))
  63.                             strcpy(argline[arglinecount++], GetStr(ST_DateA));
  64.                     if (!strcmp(pos1,"SOURCE_A"))
  65.                             strcpy(argline[arglinecount++], CYA_Source[GetCycle(CY_SourceA)]);
  66.                     if (!strcmp(pos1,"NOISER_A"))
  67.                             strcpy(argline[arglinecount++], CYA_NoiseR[GetCycle(CY_NoiseRA)]);
  68.  
  69.                     if (!strcmp(pos1,"TOPTITLE_B"))
  70.                         if (translateflag)
  71.                             strcpy(argline[arglinecount++], translate_to_latex(GetStr(ST_TitleB)));
  72.                         else
  73.                             strcpy(argline[arglinecount++], GetStr(ST_TitleB));
  74.                     if (!strcmp(pos1,"TOPGROUP_B"))
  75.                         if (translateflag)
  76.                             strcpy(argline[arglinecount++], translate_to_latex(GetStr(ST_GroupB)));
  77.                         else
  78.                             strcpy(argline[arglinecount++], GetStr(ST_GroupB));
  79.                     if (!strcmp(pos1,"DATE_B"))
  80.                             strcpy(argline[arglinecount++], GetStr(ST_DateB));
  81.                     if (!strcmp(pos1,"SOURCE_B"))
  82.                             strcpy(argline[arglinecount++], CYA_Source[GetCycle(CY_SourceB)]);
  83.                     if (!strcmp(pos1,"NOISER_B"))
  84.                             strcpy(argline[arglinecount++], CYA_NoiseR[GetCycle(CY_NoiseRB)]);
  85.  
  86.                     /* Insert the list entries */
  87.                     if (!strcmp(pos1,"TITLE_A"))
  88.                     {
  89.                         pos1 = pos2;
  90.                         pos2 = strchr(pos1, '@');
  91.                         *pos2++ = '\0';
  92.                         if (atoi(pos1) - 1 < endA)
  93.                             DoMethod(LV_SideA, MUIM_List_GetEntry, atoi(pos1) - 1, &entry);
  94.                         else
  95.                             entry = &emptynode;
  96.                         if (translateflag)
  97.                             strcpy(argline[arglinecount++], translate_to_latex(entry->title));
  98.                         else
  99.                             strcpy(argline[arglinecount++], entry->title);
  100.                     }
  101.                     if (!strcmp(pos1,"GROUP_A"))
  102.                     {
  103.                         pos1 = pos2;
  104.                         pos2 = strchr(pos1, '@');
  105.                         *pos2++ = '\0';
  106.                         if (atoi(pos1) - 1 < endA)
  107.                             DoMethod(LV_SideA, MUIM_List_GetEntry, atoi(pos1) - 1, &entry);
  108.                         else
  109.                             entry = &emptynode;
  110.                         if (translateflag)
  111.                             strcpy(argline[arglinecount++], translate_to_latex(entry->group));
  112.                         else
  113.                             strcpy(argline[arglinecount++], entry->group);
  114.                     }
  115.                     if (!strcmp(pos1,"EXTENSION_A"))
  116.                     {
  117.                         pos1 = pos2;
  118.                         pos2 = strchr(pos1, '@');
  119.                         *pos2++ = '\0';
  120.                         if (atoi(pos1) - 1 < endA)
  121.                             DoMethod(LV_SideA, MUIM_List_GetEntry, atoi(pos1) - 1, &entry);
  122.                         else
  123.                             entry = &emptynode;
  124.                         if (translateflag)
  125.                             strcpy(argline[arglinecount++], translate_to_latex(entry->extension));
  126.                         else
  127.                             strcpy(argline[arglinecount++], entry->extension);
  128.                     }
  129.  
  130.                     if (!strcmp(pos1,"TITLE_B"))
  131.                     {
  132.                         pos1 = pos2;
  133.                         pos2 = strchr(pos1, '@');
  134.                         *pos2++ = '\0';
  135.                         if (atoi(pos1) - 1 < endB)
  136.                             DoMethod(LV_SideB, MUIM_List_GetEntry, atoi(pos1) - 1, &entry);
  137.                         else
  138.                             entry = &emptynode;
  139.                         if (translateflag)
  140.                             strcpy(argline[arglinecount++], translate_to_latex(entry->title));
  141.                         else
  142.                             strcpy(argline[arglinecount++], entry->title);
  143.                     }
  144.                     if (!strcmp(pos1,"GROUP_B"))
  145.                     {
  146.                         pos1 = pos2;
  147.                         pos2 = strchr(pos1, '@');
  148.                         *pos2++ = '\0';
  149.                         if (atoi(pos1) - 1 < endB)
  150.                             DoMethod(LV_SideB, MUIM_List_GetEntry, atoi(pos1) - 1, &entry);
  151.                         else
  152.                             entry = &emptynode;
  153.                         if (translateflag)
  154.                             strcpy(argline[arglinecount++], translate_to_latex(entry->group));
  155.                         else
  156.                             strcpy(argline[arglinecount++], entry->group);
  157.                     }
  158.                     if (!strcmp(pos1,"EXTENSION_B"))
  159.                     {
  160.                         pos1 = pos2;
  161.                         pos2 = strchr(pos1, '@');
  162.                         *pos2++ = '\0';
  163.                         if (atoi(pos1) - 1 < endB)
  164.                             DoMethod(LV_SideB, MUIM_List_GetEntry, atoi(pos1) - 1, &entry);
  165.                         else
  166.                             entry = &emptynode;
  167.                         if (translateflag)
  168.                             strcpy(argline[arglinecount++], translate_to_latex(entry->extension));
  169.                         else
  170.                             strcpy(argline[arglinecount++], entry->extension);
  171.                     }
  172.  
  173.                     /* Locale Support */
  174.                     if (!strcmp(pos1,"LANG_POSITION"))
  175.                         if (translateflag)
  176.                             strcpy(argline[arglinecount++], translate_to_latex(GetLocaleString(MSG_LABEL_POSITION)));
  177.                         else
  178.                             strcpy(argline[arglinecount++], GetLocaleString(MSG_LABEL_POSITION));
  179.                     if (!strcmp(pos1,"LANG_LENGTH"))
  180.                         if (translateflag)
  181.                             strcpy(argline[arglinecount++], translate_to_latex(GetLocaleString(MSG_LABEL_LENGTH)));
  182.                         else
  183.                             strcpy(argline[arglinecount++], GetLocaleString(MSG_LABEL_LENGTH));
  184.                     if (!strcmp(pos1,"LANG_DATE"))
  185.                         if (translateflag)
  186.                             strcpy(argline[arglinecount++], translate_to_latex(GetLocaleString(MSG_LABEL_DATE)));
  187.                         else
  188.                             strcpy(argline[arglinecount++], GetLocaleString(MSG_LABEL_DATE));
  189.  
  190.                     pos1 = pos2;
  191.                 }
  192.  
  193.                 /* Begin the printing of bufline2 & argline */
  194.                 switch (arglinecount)
  195.                 {
  196.                     case 1:
  197.                         fprintf(out, bufline2, argline[0]);
  198.                         break;
  199.                     case 2:
  200.                         fprintf(out, bufline2, argline[0], argline[1]);
  201.                         break;
  202.                     case 3:
  203.                         fprintf(out, bufline2, argline[0], argline[1], argline[2]);
  204.                         break;
  205.                     case 4:
  206.                         fprintf(out, bufline2, argline[0], argline[1], argline[2], argline[3]);
  207.                         break;
  208.                     case 5:
  209.                         fprintf(out, bufline2, argline[0], argline[1], argline[2], argline[3], argline[4]);
  210.                         break;
  211.                     case 6:
  212.                         fprintf(out, bufline2, argline[0], argline[1], argline[2], argline[3], argline[4], argline[5]);
  213.                         break;
  214.                     case 7:
  215.                         fprintf(out, bufline2, argline[0], argline[1], argline[2], argline[3], argline[4], argline[5], argline[6]);
  216.                         break;
  217.                     case 8:
  218.                         fprintf(out, bufline2, argline[0], argline[1], argline[2], argline[3], argline[4], argline[5], argline[6], argline[7]);
  219.                         break;
  220.                 }
  221.  
  222.                 arglinecount = 0;
  223.                 buflineflag = 0;
  224.             }
  225.             else
  226.             {
  227.                 if (!buflineflag)
  228.                     buflineflag = 1;
  229.                 else
  230.                     fprintf(out, bufline2);
  231.  
  232.                 strcpy(bufline2, bufline1);
  233.             }
  234.             
  235.         }
  236.         /* Is the buffer full? */
  237.         if (buflineflag)
  238.             fprintf(out, bufline2);
  239.  
  240.         fclose(fh);
  241.         fclose(out);
  242.     }
  243. }
  244.  
  245.  
  246. /**********************************************************************
  247.  *                           Print output                             *
  248.  **********************************************************************/
  249. void print(void)
  250. {
  251.     char pathbuf[256], linebuf[512];
  252.     static struct TagItem ProcTags[] =
  253.     {
  254.         SYS_Input, 0,
  255.         SYS_Output, 0,
  256.         NP_Error, 0,
  257.         TAG_DONE
  258.     };
  259.  
  260.     stccpy(pathbuf, dirbuf_generate, 256);
  261.     AddPart(pathbuf, "CassLabel_out", 256);
  262.     generate_file(pathbuf);
  263.     sprintf(linebuf, "RX %s %s %s\n", GetStr(PS_PopDriver_String), pathbuf, dirbuf_generate);
  264.     ProcTags[0].ti_Data = Input();
  265.     ProcTags[1].ti_Data = Output();
  266.     ProcTags[2].ti_Data = (ULONG) stderr;
  267.     SystemTagList(linebuf, ProcTags);
  268. }
  269.